<%--
  Created by IntelliJ IDEA.
  User: TYZ
  Date: 2020/3/4
  Time: 15:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/common/common.jsp" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <div class="container-fluid">
        <div class="panel panel-primary" style="width:400px">
            <div class="panel-heading">
                <center><h1>登录</h1></center>
            </div>
            <div class="panel-body">
                <form id="loginForm">
                    <div class="form-group">
                        <label for="username">请输入账号:</label>
                        <input type="text" class="form-control" name="username" placeholder="请输入账号">
                        <div id="tips"></div>
                    </div>
                    <div class="form-group">
                        <label for="upassword">请输入密码:</label>
                        <input type="password" class="form-control" name="upassword" placeholder="请输入密码">
                        <div id="tips"></div>
                    </div>
                    <div class="form-group">
                        <label for="vcode">验证码</label>
                        <input type="text" class="form-control" name="vcode" placeholder="请输入验证码">
                        <img src="<%=path %>/code/vcode" onclick="changeImg(this)">
                    </div>
                    <button type="button" class="btn btn-success" onclick="toLogin()">登录</button>
                    <button type="button" class="btn btn-info" onclick="toRegister()">注册</button>
                </form>
            </div>
        </div>
    </div>
</body>
    <script type="text/javascript">
        function changeImg(obj){
            obj.src="<%=path %>/code/vcode?time=" + new Date().getTime();
        }

        function toRegister(){
            location.href="<%=path %>/userController/toRegister";
        }

        function toLogin(){
            $.ajax({
                url:"<%=path %>/userController/toLogin",
                type:"post",
                data:$("#loginForm").serialize(),
                dataType:"json",
                async:false,
                success:function(result){
                    if (result == 1) {
                        alert("账户不存在");
                    }else if(result == 2){
                        alert("当前账号已被冻结");
                    }else if(result == 3){
                        alert("登陆成功");
                        location.href = "<%=path %>/userController/toTreeView";
                    }else if(result == 4){
                        alert("密码错误");
                    }else if(result == 5){
                        alert("验证码错误");
                    }
                },
                error:function(result){
                    alert("系统异常,请联系陈龙处理");
                }
            })
        }
    </script>
</html>
